package com.javasm.crm.controller.goodController;

import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.CheckCriteria;
import com.javasm.crm.domin.criteria.GoodsSearchCriteria;
import com.javasm.crm.domin.criteria.ProductCriteria;
import com.javasm.crm.domin.criteria.SupplierCriteria;
import com.javasm.crm.domin.entity.productEntity.*;
import com.javasm.crm.service.productservice.*;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/16-16:40
 * @desp:
 * @since:
 */
@RestController
@RequestMapping("goods")
public class GoodsControllers {
    @Autowired
    GoodsSearchService goodsSearchService;
    @Autowired
    GoodsSupplierService goodsSupplierService;
    @Autowired
    GoodsSupplierVoService goodsSupplierVoService;
    @Autowired
    GoodsInfoService goodsInfoService;
    @Autowired
    GoodsCheckService goodsCheckService;
    @Autowired
    PriceCheckVoService priceCheckVoService;
    @GetMapping("getGoodsSearch")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<List<GoodsSearch>> getGoodsSearch(){
        List<GoodsSearch> goodsSearchs = goodsSearchService.getGoodsSearchs();
        return AxiosResult.success(goodsSearchs);
    }
    @GetMapping("priceCheckVoService")
    public AxiosResult<PageResult<PriceCheckVo>> priceCheckVoService( CheckCriteria checkCriteria) {
        PageResult<PriceCheckVo> priceCheckVoPageResult = priceCheckVoService.searchPageByCriteria(checkCriteria);
        return AxiosResult.success(priceCheckVoPageResult);
    }
    @GetMapping("goodsCheckService")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<List<GoodsCheck>> goodsCheckService(){
        List<GoodsCheck> goodsChecks = goodsCheckService.getGoodsChecks();
        return AxiosResult.success(goodsChecks);
    }
    @GetMapping("goodsSupplier")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<GoodsSupplier>> goodsSupplier(GoodsSearchCriteria goodsSearchCriteria) {
//        PageResult<ProductVo> productVoPageResult = productVoService.searchPageByCriteria(productCriteria);
        PageResult<GoodsSupplier> goodsSupplierPageResult = goodsSupplierService.searchPageByCriteria(goodsSearchCriteria);
        return AxiosResult.success(goodsSupplierPageResult);
    }
    @PostMapping("addSupplier")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> save(@RequestBody GoodsSupplier goodsSupplier) {
        int add = goodsSupplierService.add(goodsSupplier);
        return BaseController.toAxiosResult(add);
    }
    @PostMapping("addcheck")
    @ApiOperation(value = "修改学生", notes = "添加学生")
    public AxiosResult<Integer> add(@RequestBody GoodsInfo goodsInfo) {
        int update = goodsInfoService.update(goodsInfo);
        return BaseController.toAxiosResult(update);
    }
    @DeleteMapping("delete/{goodId}")
    @ApiOperation(value = "删除学生", notes = "删除学生")
    public AxiosResult<Integer> deleteTypeById(@PathVariable Integer goodId) {
        int i = goodsSupplierService.deleteById(goodId);
        return BaseController.toAxiosResult(i);
    }
    @PutMapping("editSupplier")
    @ApiOperation(value = "更新学生", notes = "更新学生")
    public AxiosResult<Integer> editSupplier(@RequestBody GoodsSupplier goodsSupplier) {
        int update = goodsSupplierService.update(goodsSupplier);
        return BaseController.toAxiosResult(update);
    }
    @GetMapping("GoodsSupplierVo")
    @ApiOperation(value = "条件查询", notes = "条件查询")// pick_status为0时的接口
    public AxiosResult<PageResult<GoodsSupplierVo>> goodsSupplierVo( SupplierCriteria supplierCriteria) {
        PageResult<GoodsSupplierVo> goodsSupplierVoPageResult = goodsSupplierVoService.searchPageByCriteria(supplierCriteria);
        return AxiosResult.success(goodsSupplierVoPageResult);
    }

    @PutMapping("updateGoodsStatus")
    @ApiOperation(value = "更新学生", notes = "更新学生")
    public AxiosResult<Integer> updateGoodsStatus(@RequestBody GoodsInfo goodsInfo) {
        int update = goodsInfoService.update(goodsInfo);
        return BaseController.toAxiosResult(update);
    }
}
